package com.jingsong.studentapp.adapter;
/*
 * @author zei , QQ:77132995, email:kazeik@163.com
 * 2021-12-18 10:07
 * 类说明:
 */

import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Build;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.TextAppearanceSpan;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;

import com.jingsong.studentapp.R;
import com.jingsong.studentapp.lister.OnItemEventListener;
import com.jingsong.studentapp.model.LessonModel;

public class MainSubItemAdapter<A> extends BaseAdapter<A> {
    @Override
    public int getLaoutView() {
        return R.layout.layout_main_subitem;
    }

    private OnItemEventListener eventListener;

    public OnItemEventListener getEventListener() {
        return eventListener;
    }

    public void setEventListener(OnItemEventListener eventListener) {
        this.eventListener = eventListener;
    }

    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    public void onBindViewHolder(@NonNull KBaseViewHolder holder, int position) {
        TextView tvClassName = (TextView) holder.getViewById(R.id.tvClassName);
        TextView tvItem1 = (TextView) holder.getViewById(R.id.tvItem1);
        TextView tvItem2 = (TextView) holder.getViewById(R.id.tvItem2);
        TextView tvTitle1 = (TextView) holder.getViewById(R.id.tvTitle1);
        TextView tvTitle2 = (TextView) holder.getViewById(R.id.tvTitle2);
        LinearLayout llItem1 = (LinearLayout) holder.getViewById(R.id.llItem1);
        LinearLayout llItem2 = (LinearLayout) holder.getViewById(R.id.llItem2);
        LinearLayout llClassItem = (LinearLayout) holder.getViewById(R.id.llClassItem);
        llClassItem.setOnClickListener(view -> {
            if (null != eventListener) {
                eventListener.onItemEvent(position);
            }

        });

        LessonModel lessonModel = (LessonModel) getDatas().get(position);

        if (position == 0) {
            tvItem1.setVisibility(View.VISIBLE);
            llItem2.setVisibility(View.VISIBLE);
            tvTitle1.setText("课时:");
            tvItem1.setText("已完成");
            tvTitle2.setText("习题:");
            switch (lessonModel.examStatus) {
                case 0:
                    tvItem2.setText("未知");
                    break;
                case 1:
                    tvItem2.setText("已完成");
                    break;
                case 2:
                    tvItem2.setText("未完成");
                    tvItem2.setTextColor(holder.getContext().getResources().getColor(R.color.red));
                    break;
                case 3:
                    tvItem2.setText("已逾期");
                    break;
            }
        } else {
            llItem2.setVisibility(View.INVISIBLE);
            tvTitle1.setText("习题:");
            switch (lessonModel.examStatus) {
                case 0:
                    tvItem1.setText("未知");
                    break;
                case 1:
                    tvItem1.setText("已观看");
                    break;
                case 2:
                    tvItem1.setText("未完成");
                    tvItem1.setTextColor(holder.getContext().getResources().getColor(R.color.red));
                    break;
                case 3:
                    tvItem1.setText("已逾期");
                    break;
            }
        }


        tvClassName.setText(lessonModel.lessonName);
    }

    private SpannableStringBuilder getSpan(Context context, String str) {
        SpannableStringBuilder ssb = new SpannableStringBuilder(str);
        TextAppearanceSpan span = new TextAppearanceSpan(null, 15, Color.RED);
        ssb.setSpan(span, 0, 2, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
        return ssb;
    }
}
